//   评论
let layer = layui.layer;

function get() {
    $.ajax({
        url: '/admin/comments',
        success: function(res, req) {
            if (res.status == 0) {
                let str = '';
                res.data.forEach(item => {
                    str += `<tr>
                                <td data-id="${item.id}" id="tt">${item.id}</td>
                                <td>${item.uname}</td>
                                <td>${item.content}</td>
                                <td>${item.cdate}</td>
                                <td>
                                    <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" data-id="${item.id}" id="del">删除</button>
                                </td>
                            </tr>`;
                });
                $('tbody').html(str);
            }
        }
    });
};
get();
$('tbody').on('click', '#del', function() {
    layer.confirm('确定删除吗', { icon: 3, title: '提示' }, (index) => {
        let id = $(this).attr('data-id');
        $.ajax({
            url: '/admin/comments/' + id,
            type: 'DELETE',
            success: function(res) {
                layer.msg(res.message);
                if (res.status == 0) {
                    get();
                };
            }
        });
    });
});